<?php
class email_model extends MY_model
{
    public $id;
    public $first_name;
    public $last_name;
    public $email;
    public $escape_packet;
    public $id_number;
    public $content;
    public $phone;
    public $modified_date;

    public function get_elements()
    {
        $query = $this->db->query("SELECT * FROM email ORDER BY id");
        return $this->to_domain_models($query->result());
    }

    public function get_element_by_id($id)
    {
        $query = $this->db->query("SELECT * FROM email WHERE id = ?",array($id));
        return $this->to_domain_model($query->row());
    }

    public function get_element_by_email_and_id_number($email,$id_number)
    {
        $query = $this->db->query("SELECT * FROM email WHERE email = ? AND id_number = ?",array($email,$id_number));
        return $query->num_rows();
    }

    public function get_element_by_email($email)
    {
        $query = $this->db->query("SELECT * FROM email WHERE email = ?",array($email));
        return $query->num_rows();
    }

    public function get_element_by_id_number($id_number)
    {
        $query = $this->db->query("SELECT * FROM email WHERE id_number = ?",array($id_number));
        return $query->num_rows();
    }


//    public function insertEmail($data)
//    {
//        $this->db->insert("email",$data);
//    }

    // -------------------------------------------------------------------------------- PRIVATE METHOD

    // Private method
    public function to_domain_model($item)
    {
        $model = new email_model();
        $model->id = isset($item->id) ? $item->id : '' ;
        $model->first_name = isset($item->first_name) ? $item->first_name : '' ;
        $model->last_name = isset($item->last_name) ? $item->last_name : '' ;
        $model->email = isset($item->email) ? $item->email : '';
        $model->escape_packet = isset($item->escape_packet) ? $item->escape_packet : '';
        $model->id_number = isset($item->id_number) ? $item->id_number : '';
        $model->content = isset($item->content) ? $item->content : '';
        $model->phone = isset($item->phone) ? $item->phone : '';
        $model->modified_date = isset($item->modified_date) ? $item->modified_date: '';
        return $model;
    }
}